#coding=utf-8
from django.db import models

# Create your models here.

class K8sInfo(models.Model):
    cluster_name = models.CharField(max_length=128, default="", null=False)
    config_file = models.TextField(max_length=1024 * 128, default="")
    api_server = models.CharField(max_length=256, null=False, default="")
    api_token = models.CharField(max_length=2048, null=False, default="")
    deleted = models.SmallIntegerField(null=False, default="")
    @classmethod
    def create(cls,**kwargs):
        k8s_info = cls(cluster_name=kwargs.get('cluster_name'), config_file=kwargs.get('config_file'),
                       api_server=kwargs.get('api_server'), api_token=kwargs.get('api_token'))
        ##判断是否传入id
        k8s_id = kwargs.get('k8s_id', None)
        if k8s_id:
            k8s_info.id = k8s_id
            k8s_info.save()
        else:
            k8s_info.save()

class bind(models.Model):
    env_name = models.CharField(max_length=128, default="", null=False)
    namespace = models.CharField(max_length=128, default="", null=False)
    k8s_cluster = models.CharField(max_length=128, default="", null=False)
    description = models.CharField(max_length=128, default="", null=False)
    deleted = models.SmallIntegerField(null=False, default=False)

    @classmethod
    def create(cls,**kwargs):
        bind_info = cls(env_name=kwargs.get('env_name'), namespace=kwargs.get('namespace'),
                       k8s_cluster=kwargs.get('k8s_cluster'), description=kwargs.get('description'))
        bind_info.save()



class project():
    name = models.CharField(max_length=128, unique=True,default="", null=False)
    description = models.CharField(max_length=128)
    ptype = models.SmallIntegerField(null=False)
    git_url = models.CharField(max_length=128,null=False)
    max_version = models.SmallIntegerField(null=False,default=7)
    nodeselector = models.CharField(max_length=255,null=False,default="")
    healthcheck = models.BooleanField(null=False,default=1)
    service_type = models.CharField(max_length=255,null=False,default="")
    replicas = models.IntegerField(null=False,default=1)
    ports = models.CharField(max_length=255,null=False,default="")
    req_mem = models.CharField(max_length=100,null=False,default="")
    req_cpu = models.CharField(max_length=100,null=False,default="")
    limit_mem = models.CharField(max_length=100,null=False,default="")
    limit_cpu = models.CharField(max_length=100,null=False,default="")
    quote_props = models.CharField(max_length=2048,null=False,default="{}")
